################################
# Definition des variables
################################
CC = g++
BIN = compiler
BIND = ./..
SRCD = Src
INCD = Inc
OBJD = ../Temporary
DEPD = ../Temporary
RESD = Res

SRC = $(wildcard $(SRCD)/*.cpp)
SRC2 = $(SRC) $(SRCD)/lexer.cpp $(SRCD)/parser.cpp
OBJ = $(SRC2:$(SRCD)%.cpp=$(OBJD)%.o)
DEP = $(OBJ:$(OBJD)%.o=$(DEPD)%.d)
CFLAGS = -W -Wall -ansi -pedantic -DDEBUG -g

################################
# Inclusion des infos de version
################################
-include version

################################
# Regles de production
################################

#
# A completer selon ce qui a ete vu en CM/TD
#

all : $(BIN)

$(BIN): $(OBJ)
	@$(CC) -I $(INCD) -o $(BIND)/$@ $^ -lfl

$(DEPD)/%.d: $(SRCD)/%.cpp
	@$(CC) -I $(INCD) $(CFLAGS) -MM -MD -o $@ -c $<

$(OBJD)/%.o: $(SRCD)/%.cpp
	@$(CC) -I $(INCD) -o $@ -c $< $(CFLAGS)

$(SRCD)/%.cpp: $(RESD)/%.l
	@flex -o $@ -c $<
	#@flex -d -o $@ -c $<

$(SRCD)/%.cpp: $(RESD)/%.y
	@bison -d -t -o $@ $<

$(SRCD)/%.hpp: $(RESD)/%.y
	@bison -d -t -o $@ $<

$(OBJD)/lexer.o : $(SRCD)/parser.hpp

-include $(DEP)

info:
	@echo "$(BIN) version: $(MAJOR).$(MINOR).$(BUILD)"
	@echo "$(BIN) commits: $(COMMIT)"

.PHONY: info clean distclean

debug: debugObj debugSrc debugDep

debugBin:
	@echo $(BIND)/$(BIN)

debugObj:
	@echo $(OBJ)

debugSrc:
	@echo $(SRC2)

debugDep:
	@echo $(DEP)

clean:
	rm -rf ../Temporary/* Src/lexer* Src/parser* $(OBJ) $(DEP)

distclean: clean
	rm -rf $(BIN)
